<?php

include_once(OBJECT_PATH . "/Component.php");
include_once(DAO_PATH . "/ComponentDAO.php");
include_once("UCController.php");

class UCAddComponent implements UCController
{
	function run()
	{
		// objects to be utilised during this use case
		$component = new Component();
		$dao = new ComponentDAO();		

		// get the variables from the php POST method
		$component->setCategory($_REQUEST['category']);
		$component->setName($_REQUEST['name']);
		$component->setDescription($_REQUEST['description']);
		$component->setStock($_REQUEST['stock']);
		$component->setPrice($_REQUEST['price']);

		
		// send the new component to the dao process the result
		$result= $dao->addComponent($component);
		if ($result == true)
		{
			echo "New component successfully added";
		}
		else
		{
			echo "Error detected, the operation was unsuccessful";
		}
	}	
}

?>